
cc.FileUtils:getInstance():addSearchPath("src")
cc.FileUtils:getInstance():addSearchPath("res")

-- CC_USE_DEPRECATED_API = true
require "cocos.init"

-- cclog
local cclog = function(...)
    print(string.format(...))
end

-- for CCLuaEngine traceback
function __G__TRACKBACK__(msg)
    cclog("----------------------------------------")
    cclog("LUA ERROR: " .. tostring(msg) .. "\n")
    cclog(debug.traceback())
    cclog("----------------------------------------")
    return msg
end

local function main()
    collectgarbage("collect")
    -- avoid memory leak
    collectgarbage("setpause", 100)
    collectgarbage("setstepmul", 5000)

    -- initialize director
    local director = cc.Director:getInstance()

    --turn on display FPS
    director:setDisplayStats(true)

    --set FPS. the default value is 1.0/60 if you don't call this
    director:setAnimationInterval(1.0 / 60)
    
    cc.Director:getInstance():getOpenGLView():setDesignResolutionSize(960, 640, 0)
    
    --create scene 
    -- local scene = require("GameScene2")
    -- local gameScene = scene.create()
    -- gameScene:playBgMusic()
	local node = cc.CSLoader:createNode('../res/MainScene.csb')
    local action = cc.CSLoader:createTimeline('../res/MainScene.csb')
    node:runAction(action)
    action:gotoFrameAndPlay(0, 30, true)
	
	local layer = cc.CSLoader:createNode('../res/Layer.csb')
	local action2 = cc.CSLoader:createTimeline('../res/Layer.csb')
	node:addChild(layer)
	layer:runAction(action2)
	action2:gotoFrameAndPlay(0, 47, false)
	
	local scene2 = cc.Scene:create()
	
	scene2:addChild(node)
	
	local gameScene = scene2
    
    if cc.Director:getInstance():getRunningScene() then
        cc.Director:getInstance():replaceScene(gameScene)
    else
        cc.Director:getInstance():runWithScene(gameScene)
    end

end


local status, msg = xpcall(main, __G__TRACKBACK__)
if not status then
    error(msg)
end
